<template>
  <div id="index">
    <div style="margin-bottom: 20px">
      <el-button   type="primary" round plain @click="$routerGo('/admin-question-info')">添加试卷</el-button>
    </div>
    <dyd-table :data="tableData" v-if="showTable">
      <el-table-column
        prop="ids"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="name"
        label="试卷名称">
      </el-table-column>
      <el-table-column
        prop="fraction"
        label="总分">
      </el-table-column>
      <el-table-column
        prop="userName"
        label="上传人员">
      </el-table-column>
      <el-table-column
        width="160"
        label="操作">
        <template slot-scope="scope">
          <dydLink  type="up" @click.native="$routerGo('/admin-question-info',scope.row)">详情</dydLink>
          <dydLink  type="del"   @click.native="deleteAdmin(scope.row,scope.$index)">删除</dydLink>
        </template>
      </el-table-column>
    </dyd-table>
  </div>
</template>

<script>
  export default {
    name: "index",
    props: [''],
    data() {
      return {
        updates:false,
        form:{
          name:'',
          fraction: 1,
        },
        ruleForm:{},
        rules:{
          name:[
            {  required: true, message: '请输入题型名称', trigger: 'blur'  },
          ]
        },
        tableData:[],
        showTable: true
      }
    },
    methods: {
      deleteAdmin(row,index){
        this.$api.del('question',{ids:row.ids},res=>{
          this.tableData.splice(index,1)
        })
      },
      getClass(){
        this.showTable = false
        let cnt = {
          $orderBY: {col:'ids'},
          $link:{
            table:'admin',
            left:'userId',
            right:'userId',
            where:'ids as userId,names as userName'
          }
        }
        this.$api.get('question',cnt,res=>{
          this.tableData.splice(0, this.tableData.length,...res)
          this.$nextTick(()=>{
            setTimeout(()=>{
              this.showTable = true
            })
          })
        })
      }
    },
    mounted() {
      this.getClass()
    },
    created() {
      this.getClass()
    },
    components: {},
    watch: {},
  }
</script>

<style scoped lang='scss'>
  #index {

  }
</style>
